<template>
  <div class="home">
    <Breadcrumb name1="首页内容"></Breadcrumb>
    <el-card>
      <div class="cnt">
        <div class="left">
          <h1 style="font-size: 24px">收货地全国分布图</h1>
          <div ref="main" style="width: 900px; height: 700px"></div>
        </div>
        <div class="right">
          <h1 style="font-size: 24px">销量统计</h1>
          <div id="myChart1" style="width: 600px; height: 600px"></div>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
import Breadcrumb from '@/components/breadcrumb'
// 引入json路径文件
import chinaJson from '@/assets/china.json'
export default {
  data() {
    return {
      chinachart: null,
    }
  },
  components: {
    Breadcrumb,
  },
  mounted() {
    this.drawLine1()
    // 另外发现的一个小tip，当注册中国地图用的不是’china’,是其他字符串，例如’CHINA’的时候，南海诸岛的会消失，这个可以当做一个工具，也可以当做一个重点用
    // 初始化echarts实例
    this.chinachart = this.$echarts.init(this.$refs.main)

    var points = [
      { value: [118.8062, 31.9208], itemStyle: { color: '#4ab2e5' } },
      { value: [127.9688, 45.368], itemStyle: { color: '#4fb6d2' } },
      { value: [110.3467, 41.4899], itemStyle: { color: '#52b9c7' } },
      { value: [113.8154, 23.2584], itemStyle: { color: '#5abead' } },
      { value: [116.4551, 40.2539], itemStyle: { color: '#f34e2b' } },
      { value: [123.1238, 42.1216], itemStyle: { color: '#f56321' } },
      { value: [114.4995, 38.1006], itemStyle: { color: '#f56f1c' } },
      { value: [117.4219, 39.4189], itemStyle: { color: '#f58414' } },
      { value: [112.3352, 37.9413], itemStyle: { color: '#f58f0e' } },
      { value: [109.1162, 34.2004], itemStyle: { color: '#f5a305' } },
      { value: [119.5901, 26.3043], itemStyle: { color: '#e7ab0b' } },
      { value: [106.3586, 38.1775], itemStyle: { color: '#dfae10' } },
      { value: [101.4038, 36.8207], itemStyle: { color: '#d5b314' } },
      { value: [103.9526, 30.7617], itemStyle: { color: '#c1bb1f' } },
      { value: [108.384366, 30.439702], itemStyle: { color: '#b9be23' } },
      { value: [113.0823, 28.2568], itemStyle: { color: '#a6c62c' } },
      { value: [102.9199, 25.46639], itemStyle: { color: '#96cc34' } },
      { value: [112.93133, 28.2351] },
    ]

    // 在这里调用路径文件
    this.$echarts.registerMap('china', chinaJson)

    const option = {
      backgroundColor: '#ffffff',
      geo: {
        map: 'china',
        aspectScale: 0.75, // 长宽比
        zoom: 1.1,
        roam: false,
        itemStyle: {
          normal: {
            areaColor: {
              type: 'radial',
              x: 0.5,
              y: 0.5,
              r: 0.8,
              colorStops: [
                {
                  offset: 0,
                  color: '#09132c', // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: '#274d68', // 100% 处的颜色
                },
              ],
              globalCoord: true, // 缺省为 false
            },
            shadowColor: 'rgb(58,115,192)',
            shadowOffsetX: 10,
            shadowOffsetY: 11,
          },
          emphasis: {
            areaColor: '#2AB8FF',
            borderWidth: 0,
            color: 'green',
            label: {
              show: false,
            },
          },
        },
        regions: [
          {
            name: '南海诸岛',
            itemStyle: {
              areaColor: 'rgba(0, 10, 52, 1)',

              borderColor: 'rgba(0, 10, 52, 1)',
              normal: {
                opacity: 0,
                label: {
                  show: false,
                  color: '#009cc9',
                },
              },
            },
          },
        ],
      },
      series: [
        {
          type: 'map',
          roam: false,
          label: {
            normal: {
              show: true,
              textStyle: {
                color: '#1DE9B6',
              },
            },
            emphasis: {
              textStyle: {
                color: 'rgb(183,185,14)',
              },
            },
          },

          itemStyle: {
            normal: {
              borderColor: 'rgb(147, 235, 248)',
              borderWidth: 1,
              areaColor: {
                type: 'radial',
                x: 0.5,
                y: 0.5,
                r: 0.8,
                colorStops: [
                  {
                    offset: 0,
                    color: '#09132c', // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: '#274d68', // 100% 处的颜色
                  },
                ],
                globalCoord: true, // 缺省为 false
              },
            },
            emphasis: {
              areaColor: 'rgb(46,229,206)',
              //    shadowColor: 'rgb(12,25,50)',
              borderWidth: 0.1,
            },
          },
          zoom: 1.1,
          //     roam: false,
          map: 'china', // 使用
        },
        {
          type: 'effectScatter',
          coordinateSystem: 'geo',
          showEffectOn: 'render',
          zlevel: 1,
          rippleEffect: {
            period: 15,
            scale: 4,
            brushType: 'fill',
          },
          hoverAnimation: true,
          label: {
            normal: {
              formatter: '{b}',
              position: 'right',
              offset: [15, 0],
              color: '#1DE9B6',
              show: true,
            },
          },
          itemStyle: {
            normal: {
              color:
                '#1DE9B6' /* function (value){ //随机颜色 return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6);
 } */,
              shadowBlur: 10,
              shadowColor: '#333',
            },
          },
          symbolSize: 12,
          data: points,
        }, // 地图线的动画效果
        {
          type: 'lines',
          zlevel: 2,
          effect: {
            show: true,
            period: 4, // 箭头指向速度，值越小速度越快
            trailLength: 0.4, // 特效尾迹长度[0,1]值越大，尾迹越长重
            symbol: 'arrow', // 箭头图标
            symbolSize: 7, // 图标大小
          },
          lineStyle: {
            normal: {
              color: '#1DE9B6' /* function (value){ //随机颜色

                        ['#f21347','#f3243e','#f33736','#f34131','#f34e2b',
                        '#f56321','#f56f1c','#f58414','#f58f0e','#f5a305',
                        '#e7ab0b','#dfae10','#d5b314','#c1bb1f','#b9be23',
                        '#a6c62c','#96cc34','#89d23b','#7ed741','#77d64c',
                        '#71d162','#6bcc75','#65c78b','#5fc2a0','#5abead',
                        '#52b9c7','#4fb6d2','#4ab2e5']
 return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6);
 } */,
              width: 1, // 线条宽度
              opacity: 0.1, // 尾迹线条透明度
              curveness: 0.3, // 尾迹线条曲直度
            },
          },
          data: [
            {
              coords: [
                [112.93133, 28.2351],
                [118.8062, 31.9208],
              ],
              lineStyle: { color: '#4ab2e5' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [127.9688, 45.368],
              ],
              lineStyle: { color: '#4fb6d2' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [110.3467, 41.4899],
              ],
              lineStyle: { color: '#52b9c7' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [113.8154, 23.2584],
              ],
              lineStyle: { color: '#5abead' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [116.4551, 40.2539],
              ],
              lineStyle: { color: '#f34e2b' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [123.1238, 42.1216],
              ],
              lineStyle: { color: '#f56321' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [114.4995, 38.1006],
              ],
              lineStyle: { color: '#f56f1c' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [117.4219, 39.4189],
              ],
              lineStyle: { color: '#f58414' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [112.3352, 37.9413],
              ],
              lineStyle: { color: '#f58f0e' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [109.1162, 34.2004],
              ],
              lineStyle: { color: '#f5a305' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [119.5901, 26.3043],
              ],
              lineStyle: { color: '#e7ab0b' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [106.3586, 38.1775],
              ],
              lineStyle: { color: '#dfae10' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [101.4038, 36.8207],
              ],
              lineStyle: { color: '#d5b314' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [103.9526, 30.7617],
              ],
              lineStyle: { color: '#c1bb1f' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [108.384366, 30.439702],
              ],
              lineStyle: { color: '#b9be23' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [113.0823, 28.2568],
              ],
              lineStyle: { color: '#a6c62c' },
            },
            {
              coords: [
                [112.93133, 28.2351],
                [102.9199, 25.46639],
              ],
              lineStyle: { color: '#96cc34' },
            },
          ],
        },
      ],
    }

    this.chinachart.setOption(option)
  },
  methods: {
    drawLine1() {
      let myChart1 = this.$echarts.init(document.getElementById('myChart1'))
      myChart1.setOption({
        dataset: {
          source: [
            ['score', 'amount', 'product'],
            [89.3, 58212, '河南'],
            [57.1, 78254, '上海'],
            [74.4, 41032, '北京'],
            [50.1, 12755, '江西'],
            [89.7, 20145, '江苏'],
            [68.1, 79146, '广东'],
            [19.6, 91852, '杭州'],
            [10.6, 101852, '湖南'],
            [32.7, 20112, '云南'],
          ],
        },
        grid: { containLabel: true },
        xAxis: { name: 'amount' },
        yAxis: { type: 'category' },
        visualMap: {
          orient: 'horizontal',
          left: 'center',
          min: 10,
          max: 100,
          text: ['hot', 'cool'],
          // Map the score column to color
          dimension: 0,
          inRange: {
            color: ['#65B581', '#FFCE34', '#FD665F'],
          },
        },
        series: [
          {
            type: 'bar',
            encode: {
              // Map the "amount" column to X axis.
              x: 'amount',
              // Map the "product" column to Y axis
              y: 'product',
            },
          },
        ],
      })
    },
  },
  created() {
    this.drawLine1()
  },
}
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  width: 100%;
  .cnt {
    display: flex;
    padding-top: 20px;
    .right {
      margin-top: -40px;
      h1 {
        margin-top: 40px;
      }
    }
  }
}
</style>
